package com.ziiwee.reduce.describe.creators.handlers;

import com.ziiwee.reduce.describe.FieldDescribe;
import com.ziiwee.reduce.describe.HttpRequestParameterType;
import com.ziiwee.reduce.describe.ResourceMethod;
import org.springframework.core.ResolvableType;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author ziiwee
 * @data 2020/8/12
 */
public class RestDeleteHandlerDescribeCreator extends AbstractRestHandlerCreator {

    private final Class<?> entityClass;
    private final Class<?> idType;
    private final String basePattern;
    public RestDeleteHandlerDescribeCreator(Class<?> entityClass, Class<?> idType, String basePattern) {
        this.entityClass = entityClass;
        this.idType = idType;
        this.basePattern = basePattern;
    }

    @Override
    public ResourceMethod getResourceMethod() {
        return ResourceMethod.DELETE;
    }

    @Override
    public Class<?> getEntityClass() {
        return entityClass;
    }

    @Override
    public String getBasePattern() {
        return basePattern;
    }

    @Override
    public ResolvableType getType() {
        return ResolvableType.forClass(void.class);
    }

    @Override
    public Map<HttpRequestParameterType, List<FieldDescribe>> getParameters() {
        FieldDescribe id = getIdProperty(ResolvableType.forClass(idType));
        Map<HttpRequestParameterType, List<FieldDescribe>> map = new HashMap<>();
        map.put(HttpRequestParameterType.PATH, Collections.singletonList(id));
        return map;
    }
}
